
# Terminl Multiplexer (Tmux)
# ============================= Concept ==================================
# 1)
# create new tmux session 
# >> tmux new -s newSessionName

# 2)
# detach ≠ exit  
# >> tmux detach 

# 3)
# when you exit, you kill the tmux session with exit command
# >> exit 

# 4)
# list all the sessions we create 
# >> tmux ls 

# 5)
# switch to any of the tmux session 
# >> tmux attach -t sessionName

# 6)
# see all session inside tmux, binded in alacritty
# navigate with j and k
# original:  prefix + s
# alacritty: cmd + u


# remap prefix key, although I can use alacritty to go around with this issues 
# but it good to know how to remap prefix, after all I still have resize pane bind with prefix
# -g means global
set -g prefix C-a 
unbind C-b 
bind-key C-a send-prefix

# shortcut for source the changes, replace with cmd+r
# you can basically save config file anywhere, just bind that path with r
bind r source-file ~/.config/tmux/tmux.conf \; display-message "========== New Changes Added! ==========="

# ================================ true color references ===================================
# https://jdhao.github.io/2018/10/19/tmux_nvim_true_color/
# enable TRUE color functionality
set -g default-terminal "screen-256color"
# tell Tmux that outside terminal supports true color
set -ga terminal-overrides ",xterm-256color*:Tc"
# for tmux 3.2, you can use the following setting instead:
# set -as terminal-features ",xterm-256color:RGB"


# split pane 
bind B split-window -v # split up and down 
bind N split-window -h # split left and right

# navigate through pane is now default options 
# prefix + left-arrow(cmd+h)
# prefix + down-arrow(cmd+j)
# prefix + up-arrow(cmd+k)
# prefix + right-arrow(cmd+l)

# resize pane 
# use captialized case of vim style arrow
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5


# maximize current pane, same key bind to recover to original size
bind -r m resize-pane -Z


# setting the color of copy-mode: 
# set -g mode-style 'reverse' 
# -> line above means follow the same setting as original terminal (in our case is alacritty's config)
set -g mode-style "fg=black,bg=green"

# ============================================ status bar ===============================================
# all instruction in the man file, format section
# status bar color
set -g status-bg "#121212"
set -g status-fg "#ffffff"

# status bar display content
set -g status-left '#[fg=#A1EFD3]#(echo "Session: ")#[fg=#A1EFD3]#{session_name}'
set -g status-left-length 25    # how many string left could show
set -g status-justify centre
set -g status-right '#[fg=#A1EFD3]#(date)'
set -g status-interval 1

# status bar display format
set -g window-status-format '#{window_index}#(echo ":")#{window_name}#{window_flags}'
set -g window-status-current-format '#[fg=#A1EFD3]#{window_index}#(echo ":")#{window_name}#{window_flags}'

# status bar position
set-option -g status-position bottom

# renumber window index after closing one
set -g renumber-windows on

# renumber the bae index
set -g base-index 1 
set -g pane-base-index 1 

# pane border colours
set -g pane-border-style fg="#3E3859"
set -g pane-active-border-style "bg=default fg=#A1EFD3"

# still trying to find way to set the highlight color in copy-mode, but the following doesn't work
# set-hook -g 'pane-mode-changed' 'set -gF status-style "bg=#{?#{==:#{pane_mode},copy-mode},red,blue}"'

# ======================= mouse ==========================
set -g mouse on




#
# set -g window-status-current-format " #I: #W "
# set -g window-status-current-style fg=red
#
# set -g status-left " #S "
# set -g status-left-style fg=red,bg=green
#
# set -g status-right " %a %h %d, %Y %l:%M %p "
# set -g status-right-style fg=green
#

# ============================================ Tmux Plugin ==============================================
# run this in the command line: 
# >> git clone 'https://github.com/tmux-plugins/tpm' ~/.config/tmux/plugins/tpm
# add the following into tmux/tmux.conf

# tpm plugin manager
set -g @plugin 'tmux-plugins/tpm'

# list of tmux plugin
# set -g @plugin 'tmux-plugins/tmux-resurrect'    # persist tmux session after computer restart
# set -g @plugin 'tmux-plugins/tmux-continuum'    # automatically saves sessions for you every 15 minutes

# set auto on for above two plugins work properly
# set -g @resurrect-capture-pane-contents 'on'
# set -g @continuum-restore 'on'


# To Reload/Install plugin --> enter tmux session --> prefix + I
# ============================================ Tmux Plugin ==============================================



# keep this line at the very bottom of tmux.conf for plugin to work properly
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
# run '~/.tmux/plugins/tpm/tpm'


